package com.lv.suyiyong.hfrbusines.adapter

import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.common.ktx.applyGrayScale
import com.lv.service.bean.CommonSelectedBean
import com.lv.suyiyong.hfrbusines.R
import com.lv.suyiyong.hfrbusines.databinding.ItemClientHfrBinding


/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class ClientsHFRAdapter(
    private val datas: MutableList<CommonSelectedBean>,
    private val showAdd: Boolean = false
) :
    BaseQuickAdapter<CommonSelectedBean, DataBindBaseViewHolder>
        (R.layout.item_client_hfr, datas) {

    override fun convert(holder: DataBindBaseViewHolder, item: CommonSelectedBean) {
        val mBinding: ItemClientHfrBinding =
            holder.getBind() as ItemClientHfrBinding
//        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
        val tag = mBinding.ivLogo.tag
//        if (tag != item.id) {
//            mBinding.ivLogo.tag = item.id
//            mBinding.ivLogo.LoadSrc(item.logo)
//        }
        mBinding.ivLogo.applyGrayScale()

//
        val mViewList = mutableListOf<View>()
        val tags = mutableListOf<String>()
        tags.add("五金工具")
        tags.add("最近活跃：15天前")

        tags.forEach { itemCategory ->
            val textChild = LayoutInflater.from(context)
                .inflate(
                    com.lv.service.R.layout.text_999_tag_layout,
                    mBinding.flowLayout, false
                ) as TextView
            val name = itemCategory
            textChild.text = name
            mViewList.add(textChild)
        }
        mBinding.flowLayout.setChildren(mViewList)

        mBinding.clParent.setOnClickListener {
            onViewClickListener?.onClick(layoutPosition, item)
        }
        mBinding.llJj.setOnClickListener { onViewJJClickListener?.onClick(layoutPosition, item) }
        mBinding.llDj.setOnClickListener { onViewDJClickListener?.onClick(layoutPosition, item) }
        mBinding.llTel.setOnClickListener { onViewTelClickListener?.onClick(layoutPosition, item) }

    }

    var onViewClickListener: OnPositionTListener<CommonSelectedBean>? = null
    var onViewJJClickListener: OnPositionTListener<CommonSelectedBean>? = null
    var onViewDJClickListener: OnPositionTListener<CommonSelectedBean>? = null
    var onViewTelClickListener: OnPositionTListener<CommonSelectedBean>? = null

}